package com.makenv.service;

import com.makenv.dao.BookMapper;
import com.makenv.domain.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {

    @Autowired
    BookMapper bookMapper;

    public int insert(String name, String author, String description, String link, String category) {

        Book book = new Book();
        book.setName(name);
        book.setAuthor(author);
        book.setDescription(description);
        book.setLink(link);
        book.setCategory(category);
        return bookMapper.insert(book);
    }

    public int getBookSum() {
        return bookMapper.getBookSum();
    }

    public int getSearchBookSum(String bookName) {
        return bookMapper.getSearchBookSum(bookName);
    }

    public List<Book> showBookList(int startRow, int num, String bookName) {
        return bookMapper.showBookList(startRow, num, bookName);
    }

    public int deleteByPrimaryKey(int id) {
        return bookMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKey(int id, String name, String author, String description, String link, String category) {

        Book book = new Book();
        book.setId(id);
        book.setName(name);
        book.setAuthor(author);
        book.setDescription(description);
        book.setLink(link);
        book.setCategory(category);
        return bookMapper.updateByPrimaryKey(book);
    }
}
